<?php


class Cms_Url extends WSB_Controller_Url
{

	/**
	 * @return string
	 */
    public static function languageListUrl()
	{
		return self::getUrl('language', 'list', null, 'cms');
    }

    /**
     * @param string $iso
     * @return string
     */
    public static function languageAddUrl($iso)
	{
		return self::getUrl('language', 'add', array('iso' => strtolower($iso)), 'cms');
    }

    /**
     * @param SimpleXMLElement $language
     * @return string
     */
    public static function languageAddLinkCallback(SimpleXMLElement $language)
	{
		return WSB_Controller_Url::getHtmlLink(WSB_Icon::add(), self::languageAddUrl($language->iso));
    }

	/**
	 * @return string
	 */
	public static function placeholderListUrl()
	{
		return self::getUrl('placeholder', 'list', null, 'cms');
	}

	/**
	 * @return string
	 */
	public static function placeholderDeleteUnusedUrl()
	{
		return self::getUrl('placeholder', 'deleteunused', null, 'cms');
	}

	/**
	 * @return string
	 */
	public static function placeholderDeleteUnusedConfirmedUrl()
	{
		return self::getUrl('placeholder', 'deleteunused', array('confirmed' => 'yes'), 'cms');
	}

	/**
	 * @param integer $instance_id
	 * @return string
	 */
    public static function xtensionDefaultEditorUrl($instance_id)
	{
        $table = new Cms_Model_DbTable_Xtension();
        $where = $table->getAdapter()->quoteInto('id=?', $instance_id);
        $row = $table->fetchRow($where);
        if($row instanceof Cms_Model_Xtension) {
            //$referer = $_SERVER['REQUEST_URI'];
            //return self::getUrl('index', 'index', array('instance_id' => $instance_id), 'xt'.strtolower($row->class), array('setReferer' => urlencode($referer)));
            return self::getUrl('index', 'index', array('instance_id' => $instance_id), 'xt'.strtolower($row->class));
        }
    }

    /**
     * @param integer $idcontainer
     * @param WSB_Xtension_Base $extension
     * @param string $redirect
     * @param boolean $popup
     * @return string
     */
	public static function xtensionEditorUrl($idcontainer, WSB_Xtension_Base $extension, $redirect=null, $popup=false)
	{
	    $module = $extension->getModule();
	    $container = $extension->getContainer();
        $globals = array();
        if($popup) {
            $globals['TEMPLATE'] = 'popup';
        }
        if(!empty($redirect)) {
			$globals['redirect'] = $redirect;
        }

        // Flex
        if(method_exists($extension, 'editorUrl')) {
            return $extension->editorUrl($idcontainer, $globals);
        } elseif($extension instanceof WSB_Xtension_Content) {
	       return self::getUrl('index', 'edit', array('id' => $container->item_id), 'xt'.strtolower($module->class), $globals);
        } else {
	       return self::getUrl('index', 'list', array('instance_id' => $module->id), 'xt'.strtolower($module->class), $globals);
        }

	}

	/**
	 * @param string $class
	 * @return string
	 */
	public static function xtensionDoAddUrl($class)
	{
		return self::getUrl('xtension', 'do-add', array('class' => $class), 'cms');
	}

	/**
	 * @param boolean $popup
	 * @return string
	 */
    public static function pageOverviewUrl($popup=false)
	{
        $globals = $popup ? array('TEMPLATE' => 'popup') : array();
    	return self::getUrl('page', 'tree', null, 'cms', $globals);
    }

    /**
     * @return string
     */
    public static function pageAddUrl()
	{
    	return self::getUrl('page', 'add', null, 'cms');
    }

    /**
     * @param integer $page_id
     * @return string
     */
    public static function pageHideUrl($page_id)
	{
		return self::getUrl('page', 'hide', array('page_id' => $page_id), 'cms');
    }

    /**
     * @param integer $page_id
     * @return string
     */
    public static function pageUnhideUrl($page_id)
	{
		return self::getUrl('page', 'unhide', array('page_id' => $page_id), 'cms');
    }

    /**
     * @param integer $page_id
     * @return string
     */
    public static function pageEditUrl($page_id)
	{
		return self::getUrl('page', 'edit', array('page_id' => $page_id), 'cms');
    }

    /**
     * @param integer $page_id
     * @param integer $pid
     * @return string
     */
    public static function pageDeleteUrl($page_id, $pid)
	{
		return self::getUrl('page', 'delete', array('page_id' => $page_id, 'pid' => $pid), 'cms');
	}

	/**
	 * @param integer $page_id
	 * @return string
	 */
	public static function pageCutUrl($page_id)
	{
		return self::getUrl('page', 'cut', array('page_id' => $page_id), 'cms');
	}

	/**
	 * @param integer $pid
	 * @param integer $sort
	 * @return string
	 */
	public static function pageAddBeforeUrl($pid, $sort)
	{
		return self::getUrl('page', 'add', array('pid' => $pid, 'sort' => $sort), 'cms');
	}

	/**
	 * @param integer $pid
	 * @param integer $sort
	 * @return string
	 */
	public static function pageAddBelowUrl($pid, $sort)
	{
		return self::getUrl('page', 'add', array('pid' => $pid, 'sort' => $sort), 'cms');
	}

	/**
	 * @param integer $pid
	 * @return string
	 */
	public static function pageAddChildUrl($pid)
	{
		return self::getUrl('page', 'add', array('pid' => $pid, 'sort' => 0), 'cms');
	}

	/**
	 * @param integer $cutIdPage
	 * @param integer $pid
	 * @param integer $sort
	 * @return string
	 */
	public static function pagePasteBeforeUrl($cutIdPage, $pid, $sort)
	{
		return self::getUrl('page', 'paste', array('cutIdPage' => $cutIdPage, 'pid' => $pid, 'sort' => $sort), 'cms');
	}

	/**
	 * @param integer $cutIdPage
	 * @param integer $pid
	 * @param integer $sort
	 * @return string
	 */
	public static function pagePasteBelowUrl($cutIdPage, $pid, $sort)
	{
		return self::getUrl('page', 'paste', array('cutIdPage' => $cutIdPage, 'pid' => $pid, 'sort' => $sort), 'cms');
	}

	/**
	 * @param integer $cutIdPage
	 * @param integer $pid
	 * @return string
	 */
	public static function pagePasteChildUrl($cutIdPage, $pid)
	{
		return self::getUrl('page', 'paste', array('cutIdPage' => $cutIdPage, 'pid' => $pid, 'sort' => 0), 'cms');
	}

	/**
	 * @param integer $id
	 * @param boolean $popup
	 * @return string
	 */
    public static function containerConfigurationUrl($id, $popup=false)
	{
        $globals = $popup ? array('TEMPLATE' => 'popup') : array();
    	return self::getUrl('container', 'configuration', array('id' => $id), 'cms', $globals);
    }

    /**
     * @param integer $page_id
     * @return string
     */
    public static function containerEditUrl($page_id=0)
	{
		$parameters = array();
		if(!empty($page_id)) {
			$parameters = array('page_id' => $page_id);
		}
    	return self::getUrl('container', 'edit', $parameters, 'cms');
    }

    /**
     * @param integer $page_id
     * @param integer $placeholder_id
     * @param integer $sort
     * @param integer $instance_id
     * @param integer $language_id
     * @param string $controller
     * @return string
     */
    public static function containerAddContainerUrl($page_id, $placeholder_id, $sort, $instance_id, $language_id, $controller)
	{
		return self::getUrl('container', 'add-container', array('page_id' => $page_id, 'placeholder_id' => $placeholder_id, 'sort' => $sort, 'instance_id' => $instance_id, 'language_id' => $language_id, 'fectrl' => $controller), 'cms');
    }

    /**
     * @param integer $page_id
     * @param integer $placeholder_id
     * @param integer $sort
     * @param integer $language_id
     * @param boolean $popup
     * @return string
     */
    public static function containerSelectModuleUrl($page_id, $placeholder_id, $sort, $language_id, $popup=false)
	{
        $globals = $popup ? array('TEMPLATE' => 'popup') : array();
		return self::getUrl('container', 'select-module', array('page_id' => $page_id, 'placeholder_id' => $placeholder_id, 'sort' => $sort, 'language_id' => $language_id), 'cms', $globals);
    }

    /**
     * @param integer $page_id
     * @param integer $placeholder_id
     * @param integer $sort
     * @param integer $instance_id
     * @param integer $language_id
     * @return string
     */
    public static function containerSelectControllerUrl($page_id, $placeholder_id, $sort, $instance_id, $language_id)
	{
		return self::getUrl('container', 'select-controller', array('page_id' => $page_id, 'placeholder_id' => $placeholder_id, 'sort' => $sort, 'instance_id' => $instance_id, 'language_id' => $language_id), 'cms');
    }

    /**
     * @param integer $idcontainer
     * @param integer $page_id
     * @param boolean $popup
     * @return string
     */
    public static function containerDeleteContainerUrl($idcontainer, $page_id, $popup=false)
	{
        $globals = $popup ? array('TEMPLATE' => 'popup') : array();
		return self::getUrl('container', 'delete-container', array('idcontainer' => $idcontainer, 'page_id' => $page_id), 'cms', $globals);
    }

    /**
     * @param integer $page_id
     * @param integer $idcontainer
     * @param string $redirectUrl
     * @return string
     */
    public static function containerMoveUpUrl($page_id, $idcontainer, $redirectUrl=null)
	{
        $globals = is_string($redirectUrl) ? array('REDIRECT' => $redirectUrl) : array();
		return self::getUrl('container', 'move-up', array('idcontainer' => $idcontainer, 'page_id' => $page_id), 'cms', $globals);
    }

    /**
     * @param integer $page_id
     * @param integer $idcontainer
     * @param string $redirectUrl
     * @return string
     */
    public static function containerMoveDownUrl($page_id, $idcontainer, $redirectUrl=null)
	{
        $globals = is_string($redirectUrl) ? array('REDIRECT' => $redirectUrl) : array();
		return self::getUrl('container', 'move-down', array('idcontainer' => $idcontainer, 'page_id' => $page_id), 'cms', $globals);
    }

    /**
     * @param integer $page_id
     * @param integer $container_id
     * @param string $redirectUrl
     * @return string
     */
    public static function containerHideUrl($page_id, $container_id, $redirectUrl=null)
	{
        $globals = is_string($redirectUrl) ? array('REDIRECT' => $redirectUrl) : array();
		return self::getUrl('container', 'hide', array('page_id' => $page_id, 'container_id' => $container_id), 'cms', $globals);
    }

    /**
     * @param integer $page_id
     * @param integer $container_id
     * @param string $redirectUrl
     * @return string
     */
    public static function containerUnhideUrl($page_id, $container_id, $redirectUrl=null)
	{
        $globals = is_string($redirectUrl) ? array('REDIRECT' => $redirectUrl) : array();
		return self::getUrl('container', 'unhide', array('page_id' => $page_id, 'container_id' => $container_id), 'cms', $globals);
    }

    public static function containerAddFlexUrl($page_id, $placeholder_id, $sort, $instance_id, $language_id, $controller)
	{
		return self::getUrl('container', 'add-container', array('page_id' => $page_id, 'placeholder_id' => $placeholder_id, 'sort' => $sort, 'instance_id' => $instance_id, 'language_id' => $language_id, 'fectrl' => $controller), 'cms');
    }

}
